home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / i-cpp.ads < prev    next >
Text File  |  1996-01-30  |  6KB  |  140 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                       I N T E R F A C E S . C P P                        --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.2 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
  22. --                                                                          --
  23. ------------------------------------------------------------------------------
  24.  
  25. --  Definitions for interfacing to C++ classes
  26.  
  27. with System;
  28. with System.Storage_Elements;
  29.  
  30. package Interfaces.CPP is
  31.  
  32.    --  This package corresponds to Ada.Tags but applied to tagged types
  33.    --  which are 'imported' from C++ and correspond to exactly to a C++
  34.    --  Class.  GNAT doesn't know about the structure od the C++ dispatch
  35.    --  table (Vtable) but always access it through the procedural interface
  36.    --  defined below, thus the iplementation of this package (the body) can
  37.    --  be customized to another C++ compiler without any change in the
  38.    --  compiler code itself as long as this procedural interface is
  39.    --  respected. Note that Ada.Tags defines a very similar procedural
  40.    --  interface to the regular Ada Dispatch Table.
  41.  
  42.    type Vtable_Ptr is private;
  43.  
  44. private
  45.  
  46.    --  Note: these procedures are accessible to Rtsfind, but not visible
  47.    --  to a user who with's the package to get the Vtable_Ptr declaration.
  48.  
  49.    procedure Set_Vfunction_Address
  50.     (Vptr      : Vtable_Ptr;
  51.       Position : Positive;
  52.       Value    : System.Address);
  53.    --  Given a pointer to a Vtable (Vptr) and a position in the
  54.    --  Vtable, put the address of the virtual function in it.
  55.    --  (used for overriding)
  56.  
  57.    function Get_Vfunction_Address
  58.      (Vptr     : Vtable_Ptr;
  59.       Position : Positive)
  60.       return     System.Address;
  61.    --  Given a pointer to a Vtable (Vptr) and a position in the Vtable, this
  62.    --  function returns the address of the virtual function stored in it.
  63.    --  (used for dispatching calls)
  64.  
  65.    procedure Set_Idepth
  66.      (Vptr  : Vtable_Ptr;
  67.       Value : Natural);
  68.    --  Given a pointer to a Vtable, stores the value representing
  69.    --  the depth in the inheritance tree.
  70.    --  (used during elaboration of the tagged type)
  71.  
  72.    function  Get_Idepth (Vptr : Vtable_Ptr) return Natural;
  73.    --  Given a pointer to a Vtable, retreives the value representing
  74.    --  the depth in the inheritance tree.
  75.    --  (used for membership)
  76.  
  77.    procedure Set_Ancestor_Vptrs
  78.      (Vptr  : Vtable_Ptr;
  79.       Value : System.Address);
  80.    --  Given a pointer to a Vtable, stores the address of a table that can
  81.    --  be used to store the Vptrs of the ancestors, this table is statically
  82.    --  allocated by the compiler along with the Dispatch Table (Vtable) with
  83.    --  a sufficient size to store all Vptrs ancestors in order to match the
  84.    --  canonical implementation of membership test (see Ada.Tags for details).
  85.    --  (used during elaboration of the tagged type)
  86.  
  87.    function  Get_Ancestor_Vptrs (Vptr : Vtable_Ptr) return System.Address;
  88.    --  Given a pointer to a Vtable, retreives the address of a
  89.    --  table containing the Vptrs of the ancestors.
  90.    --  (used for membership)
  91.  
  92.    function Displaced_This
  93.     (Current_This : System.Address;
  94.      Vptr         : Vtable_Ptr;
  95.      Position     : Positive)
  96.      return         System.Address;
  97.    --  Compute the displacement on the "this" pointer in order to be
  98.    --  compatible with MI.
  99.    --  (used for virtual function calls)
  100.  
  101.    function Vtable_Size
  102.      (Entry_Count : Natural)
  103.       return        System.Storage_Elements.Storage_Count;
  104.    --  Compute the size in 'storage_count' of a vtable of the given size
  105.    --  (used to statically create the vtable)
  106.  
  107.    procedure Inherit_Vtable
  108.     (Old_Vptr    : Vtable_Ptr;
  109.      New_Vptr    : Vtable_Ptr;
  110.      Entry_Count : Natural);
  111.    --  The Vtable referenced by New_Vptr "inherits" the Entry_Count first
  112.    --  entries of the Vtable referenced by Old_Vptr. This function is also
  113.    --  responsible for inheriting the type specific information used for
  114.    --  the membership implementation
  115.    --  (used to initialize a new Vtable)
  116.  
  117.    function CPP_Membership
  118.      (Obj_Vptr : Vtable_Ptr;
  119.       Typ_Vptr : Vtable_Ptr)
  120.       return Boolean;
  121.    --  Given the tag of an object and the tag associated to a type, return
  122.    --  true if Obj is in Typ'Class.
  123.    --  (used for classwide membership test)
  124.  
  125.    type Vtable;
  126.    type Vtable_Ptr is access all Vtable;
  127.  
  128.    pragma Inline (Set_Vfunction_Address);
  129.    pragma Inline (Get_Vfunction_Address);
  130.    pragma Inline (Set_Idepth);
  131.    pragma Inline (Get_Idepth);
  132.    pragma Inline (Set_Ancestor_Vptrs);
  133.    pragma Inline (Get_Ancestor_Vptrs);
  134.    pragma Inline (Displaced_This);
  135.    pragma Inline (Vtable_Size);
  136.    pragma Inline (Inherit_Vtable);
  137.    pragma Inline (CPP_Membership);
  138.  
  139. end Interfaces.CPP;
  140.